package Boke2;
class Animal{
     private  String name;
    private int age;
    //通过工厂方法对构造方法进行包装。
    public static Animal create(String name1,int age1){
        System.out.println("通过工厂方法实例化的对象");
        Animal cat=new Animal();
        cat.name=name1;
        cat.age=age1;
        return cat;
    }
    public Animal(String name1,int age1){
        this.name=name1;
        this.age=age1;
        System.out.println("通过构造方法实例化的对象");
    }

    public Animal(){

    }

    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class demo1 {
    public static void main(String[] args) {
        Animal cat1=new Animal("小黄",55);
        System.out.println(cat1);
        Animal cat2=Animal.create("老黄",99);
        System.out.println(cat2);
    }
}
